home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / test / vector.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  3.3 KB  |  105 lines  |  [TEXT/R*ch]

  1. (* test/vector.sml -- some test cases for Vector 
  2.    PS 1994-12-10, 1995-06-14, 1997-03-07 *)
  3.  
  4. use "auxil.sml";
  5.  
  6. local
  7.     open Vector;
  8.     infix 9 sub;
  9. in
  10.  
  11. val a = fromList [0,1,2,3,4,5,6];
  12. val b = fromList [44,55,66];
  13. val c = fromList [0,1,2,3,4,5,6];
  14.  
  15. val test1 = check'(fn _ => a<>b);
  16. val test2 = check'(fn _ => a=c);
  17.  
  18. val d = tabulate(100, fn i => i mod 7);
  19.  
  20. val test3 = check'(fn _ => d sub 27 = 6);
  21.  
  22. val test4a = (tabulate(maxLen+1, fn i => i) seq "WRONG")
  23.              handle Size => "OK" | _ => "WRONG";
  24.  
  25. val test4b = (tabulate(~1, fn i => i)       seq "WRONG")
  26.              handle Size => "OK" | _ => "WRONG";
  27.  
  28. val test4c = check'(fn _ => length (tabulate(0, fn i => i div 0)) = 0);
  29.  
  30. val test5 = check'(fn _ => length (fromList []) = 0 andalso length a = 7);
  31.  
  32. val test6a = (c sub ~1 seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  33. val test6b = (c sub 7  seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  34. val test6c = check'(fn _ => c sub 0 = 0);
  35.  
  36. val e = concat [d, b, d];
  37.  
  38. val test7 = check'(fn _ => length e = 203);
  39.  
  40. val test8 = check'(fn _ => length (concat []) = 0);
  41.  
  42. val f = extract (e, 100, SOME 3);
  43.  
  44. val test9 = check'(fn _ => f = b);
  45.  
  46. val test9a = check'(fn _ => e = extract(e, 0, SOME (length e)) 
  47.             andalso e = extract(e, 0, NONE));
  48. val test9b = check'(fn _ => fromList [] = extract(e, 100, SOME 0));
  49. val test9c = (extract(e, ~1, SOME (length e))  seq "WRONG") 
  50.              handle Subscript => "OK" | _ => "WRONG"
  51. val test9d = (extract(e, length e + 1, SOME 0)  seq "WRONG") 
  52.              handle Subscript => "OK" | _ => "WRONG"
  53. val test9e = (extract(e, 0, SOME (length e+1)) seq "WRONG") 
  54.              handle Subscript => "OK" | _ => "WRONG"
  55. val test9f = (extract(e, 20, SOME ~1)        seq "WRONG") 
  56.              handle Subscript => "OK" | _ => "WRONG"
  57. val test9g = (extract(e, ~1, NONE)  seq "WRONG") 
  58.              handle Subscript => "OK" | _ => "WRONG"
  59. val test9h = (extract(e, length e + 1, NONE)  seq "WRONG") 
  60.              handle Subscript => "OK" | _ => "WRONG"
  61. val test9i = check'(fn _ => fromList [] = extract(e, length e, SOME 0)
  62.             andalso fromList [] = extract(e, length e, NONE));
  63.  
  64. fun chkiter iter f vec reslast =
  65.     check'(fn _ =>
  66.        let val last = ref ~1
  67.            val res = iter (fn x => (last := x; f x)) vec
  68.        in (res, !last) = reslast end)
  69.  
  70. fun chkiteri iter f vec reslast =
  71.     check'(fn _ =>
  72.        let val last = ref ~1
  73.            val res = iter (fn (i, x) => (last := i; f x)) vec
  74.        in (res, !last) = reslast end)
  75.  
  76. val test10a = 
  77.     chkiter map (fn x => 2*x) b (fromList [88,110,132], 66)
  78.  
  79. val test11a = 
  80.     chkiteri mapi (fn x => 2*x) (b, 0, NONE) (fromList [88,110,132], 2)
  81. val test11b = 
  82.     chkiteri mapi (fn x => 2*x) (b, 1, NONE) (fromList [110,132], 2)
  83. val test11c = 
  84.     chkiteri mapi (fn x => 2*x) (b, 1, SOME 0) (fromList [], ~1)
  85. val test11d = 
  86.     chkiteri mapi (fn x => 2*x) (b, 1, SOME 1) (fromList [110], 1)
  87. val test11e = 
  88.     chkiteri mapi (fn x => 2*x) (b, 3, NONE) (fromList [], ~1)
  89.  
  90. val test11f =
  91.     (mapi #2 (b, 0, SOME 4) seq "WRONG") 
  92.     handle Subscript => "OK" | _ => "WRONG";
  93. val test11g =
  94.     (mapi #2 (b, 3, SOME 1) seq "WRONG") 
  95.     handle Subscript => "OK" | _ => "WRONG";
  96. val test11h =
  97.     (mapi #2 (b, 4, SOME 0) seq "WRONG") 
  98.     handle Subscript => "OK" | _ => "WRONG";
  99. val test11i =
  100.     (mapi #2 (b, 4, NONE) seq "WRONG") 
  101.     handle Subscript => "OK" | _ => "WRONG";
  102. end;
  103.  
  104.  
  105.